package cl.tieba.resource;

import static tieba.core.utils.ReturnType.success;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import tieba.core.entity.Tie;
import tieba.core.entity.TieBar;
import tieba.core.entity.TiebaUser;
import tieba.core.utils.TBUtils;
import tieba.core.utils.entity.Result;
import water.tieba.utils.WaterUtils;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@Path("watering")
@Api("灌水")
@Produces(MediaType.APPLICATION_JSON)
public class WateringResource {
	@POST
	@ApiOperation(response = Result.class, value = "[用户]回帖")
	@Path("/p")
	public Response water(@ApiParam("灌水数量") @QueryParam("count") Integer count,
			@ApiParam("帖子URL") @QueryParam("url") String url,
			@ApiParam("灌水内容") @QueryParam("content") String content,
			@ApiParam("贴帖用户对象") TiebaUser user) {
		WaterUtils.reply(TBUtils.login(user).getBDUSS(), content, url);
		return success();
	}

	@POST
	@ApiOperation(response = Result.class, value = "[Coookie]回帖")
	@Path("/p/{cookie}")
	public Response water(
			@ApiParam("Cookie") @PathParam("cookie") String cookie,
			@ApiParam("灌水数量") @QueryParam("count") Integer count,
			@ApiParam("帖子URL") @QueryParam("url") String url,
			@ApiParam("灌水内容") @QueryParam("content") String content) {
		WaterUtils.reply(cookie, content, url);
		return success();
	}

	@POST
	@ApiOperation(response = Result.class, value = "[Cookie]发帖")
	@Path("/{cookie}")
	public Response water(
			@ApiParam("Cookie") @PathParam("cookie") String cookie,
			@ApiParam("灌水数量") @QueryParam("count") Integer count,
			@ApiParam("吧名称") @QueryParam("barName") String barName,
			@ApiParam("帖子对象") Tie tie) {
		WaterUtils.sendTie(cookie, new TieBar(barName), tie);
		return success();
	}
}
